package com.xiaoyuanxing.demo.mapper;

import com.github.pagehelper.Page;
import com.xiaoyuanxing.demo.entity.TalkComment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/*
 **@author LuoShengYing
 **@date 2021/5/28
 */
@Mapper
public interface TalkCommentMapper {

    // 根据talkID查询共有多少条TalkComment数据
    @Select("select count(*) from `talkcomment` where `talkID` = #{talkID}")
    int selectTalkCommentCount(int talkID);

    // 根据talkID查询评论数组
    @Select("select * from `talkcomment` where `talkID` = #{talkID}  ORDER BY `commentTime`")
    Page<TalkComment> selectTalkComments(int talkID);

    // 新增评论
    @Insert("insert `talkcomment` set" +
            "`talkID` = #{talkID}, `commentatorOpenID` = #{commentatorOpenID}, " +
            "`commentTime` = #{commentTime}, `comment` = #{comment}")
    boolean insertTalkComment(TalkComment talkComment);

    // 根据talkID删除全部评论
    @Delete("delete from `talkcomment` where `talkID` = #{talkID}")
    boolean deleteTalkComments(int talkID);
}
